const state = {
  receiptList: [], // 待打印小票列表
  voiceList: [], // 语音播报列表
  invoiceList: [] // 发票pdf地址
}

const mutations = {
  addToReceiptList (state, payload) {
    // TODO 判断当前记录是否已存在队列中，存在则忽略，不存在则添加
    state.receiptList.push(payload)
  },
  addToVoiceList (state, payload) {
    // TODO 判断当前记录是否已存在队列中，存在则忽略，不存在则添加
    state.voiceList.push(payload)
  },
  popReceiptList (state) {
    // 移除待打印小票，删除第一条记录
    if (state.receiptList.length > 0) {
      state.receiptList = state.receiptList.slice(1)
    }
  },
  popVoiceList (state) {
    // 移除待播报记录，删除第一条记录
    if (state.voiceList.length > 0) {
      state.voiceList = state.voiceList.slice(1)
    }
  },
  clearReceiptList (state) {
    state.receiptList = []
  },
  clearVoiceList (state) {
    state.voiceList = []
  },
  addToInvoiceList (state, payload) {
    state.invoiceList.push(payload)
  },
  popInvoiceList (state) {
    if (state.invoiceList.length > 0) {
      state.invoiceList = state.invoiceList.slice(1)
    }
  },
  clearInvoiceList (state) {
    state.invoiceList = []
  }
}

const getters = {
  receiptList: state => state.receiptList,
  voiceList: state => state.voiceList,
  invoiceList: state => state.invoiceList
}
const actions = {
  addToReceiptList ({commit}, payload) {
    commit('addToReceiptList', payload)
  },
  popReceiptList ({commit}, payload) {
    commit('popReceiptList', payload)
  },
  addToVoiceList ({commit}, payload) {
    commit('addToVoiceList', payload)
  },
  popVoiceList ({commit}, payload) {
    commit('popVoiceList', payload)
  },
  clearReceiptAndVoiceList ({commit}) {
    commit('clearReceiptList')
    commit('clearVoiceList')
    commit('clearInvoiceList')
  },
  addToInvoiceList ({commit}, payload) {
    commit('addToInvoiceList', payload)
  },
  popInvoiceList ({commit}, payload) {
    commit('popInvoiceList', payload)
  }
}

export default {
  state,
  mutations,
  getters,
  actions
}
